import java.util.Scanner;

public class ATM {
    private double balance;
    private Scanner scanner;

    public ATM(){
        this.balance = 0.0;
        this.scanner = new Scanner(System.in);
    }

    public void start() {
        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1. 存款");
            System.out.println("2. 取款");
            System.out.println("3. 显示余额");
            System.out.println("4. 退出");
            int choice = scanner.nextInt();
            scanner.nextLine(); // 消耗掉换行符

            switch (choice) {
                case 1:
                    deposit();
                    break;
                case 2:
                    withdraw();
                    break;
                case 3:
                    displayBalance();
                    break;
                case 4:
                    System.out.println("感谢使用ATM机，再见！");
                    return;
                default:
                    System.out.println("无效的选择，请重新选择。");
            }
        }
    }

    private void deposit() {
        System.out.print("请输入存款金额：");
        double amount = scanner.nextDouble();
        balance += amount;
        System.out.println("存款成功，当前余额为：" + balance);
    }

    private void withdraw() {
        System.out.print("请输入取款金额：");
        double amount = scanner.nextDouble();
        if (amount > balance) {
            System.out.println("余额不足，取款失败。");
        } else {
            balance -= amount;
            System.out.println("取款成功，当前余额为：" + balance);
        }
    }

    private void displayBalance() {
        System.out.println("当前余额为：" + balance);
    }

    public static void main(String[] args) {
        ATM atm = new ATM();
        atm.start();
    }
}
